#!/usr/bin/env bash

################################################################################
# Runs mypy on the repository using a preconfigured mypy.ini file.
#
# Usage:
#     check/mypy [--flags]
################################################################################

# Get the working directory to the repo root.
thisdir=$(dirname "${BASH_SOURCE[0]:?}") || exit $?
repo_dir=$(git -C "${thisdir}" rev-parse --show-toplevel) || exit $?
cd "${repo_dir}" || exit $?

CONFIG_FILE='mypy.ini'

read -r -a CIRQ_PACKAGES < \
    <(env PYTHONPATH=. python dev_tools/modules.py list --mode package-path)

echo -e -n "\033[31m"
mypy --config-file=dev_tools/conf/$CONFIG_FILE "$@" "${CIRQ_PACKAGES[@]}" dev_tools examples
result=$?
echo -e -n "\033[0m"

exit ${result}
